package com.ruoyi.livesass.api.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.livesass.api.convert.LbsGkscDayConvert;
import com.ruoyi.livesass.api.domain.LbsGkscDay;
import com.ruoyi.livesass.api.pojo.query.LbsGkscDayQuery;
import com.ruoyi.livesass.api.service.LbsGkscDayService;
import com.ruoyi.livesass.api.sync.ExportZbjGksc;

import cn.hutool.core.util.StrUtil;

import com.ruoyi.livesass.api.pojo.vo.LbsGkscDayVO;
import com.ruoyi.common.utils.poi.ExcelUtil;
/**
 * 用户每日观看时长Controller
 *
 * @author ydb
 * @date 2025-03-03
 */
@Api(description ="用户每日观看时长接口列表")
@RestController
@RequestMapping("/api/lbsGkscDay")
public class LbsGkscDayController extends BaseController {
    @Autowired
    private LbsGkscDayService service;
    @Autowired
    private LbsGkscDayConvert convert;
    
    @Autowired
    private ExportZbjGksc exportZbjGksc;
    
    
    //TODO 导出这里需优化
    @ApiOperation("根据直播间ID导出观看时长列表")
    @PreAuthorize("@ss.hasPermi('lbs:lbsGkscDay:export')")
    @Log(title = "用户每日观看时长", businessType = BusinessType.EXPORT)
    @GetMapping("/exportZbjId")
    public ResponseEntity<String> exportZbjId(long zbjid) {
        List<LbsGkscDay> list = exportZbjGksc.exportGkscToDay(zbjid); 
        ExcelUtil<LbsGkscDayVO> util = new ExcelUtil<>(LbsGkscDayVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "用户每日观看时长数据"));
    }
    
    

    @ApiOperation("查询用户每日观看时长列表")
    @PreAuthorize("@ss.hasPermi('lbs:lbsGkscDay:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<LbsGkscDay>> list(@RequestBody LbsGkscDayQuery query, Pageable page) {
        List<LbsGkscDay> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @ApiOperation("导出用户每日观看时长列表")
    @PreAuthorize("@ss.hasPermi('lbs:lbsGkscDay:export')")
    @Log(title = "用户每日观看时长", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(LbsGkscDayQuery query) {
        List<LbsGkscDay> list = service.selectList(query, null);
        ExcelUtil<LbsGkscDayVO> util = new ExcelUtil<>(LbsGkscDayVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "用户每日观看时长数据"));
    }

    @ApiOperation("获取用户每日观看时长详细信息")
    @PreAuthorize("@ss.hasPermi('lbs:lbsGkscDay:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<LbsGkscDay> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectById(id));
    }

    @ApiOperation("新增用户每日观看时长")
    @PreAuthorize("@ss.hasPermi('lbs:lbsGkscDay:add')")
    @Log(title = "用户每日观看时长", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody LbsGkscDay lbsGkscDay) {
        return ResponseEntity.ok(service.insert(lbsGkscDay));
    }

    @ApiOperation("修改用户每日观看时长")
    @PreAuthorize("@ss.hasPermi('lbs:lbsGkscDay:edit')")
    @Log(title = "用户每日观看时长", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody LbsGkscDay lbsGkscDay) {
        return ResponseEntity.ok(service.update(lbsGkscDay));
    }

    @ApiOperation("删除用户每日观看时长")
    @PreAuthorize("@ss.hasPermi('lbs:lbsGkscDay:remove')")
    @Log(title = "用户每日观看时长", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }
}
